package cn.beforedark.yygh.hosp.controller.api;


import cn.beforedark.yygh.common.result.R;
import cn.beforedark.yygh.hosp.service.DepartmentService;
import cn.beforedark.yygh.hosp.service.HospitalSetService;
import cn.beforedark.yygh.model.hosp.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 科室相关
 */
@RestController
@RequestMapping("/api/hosp")
public class ApiDepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private HospitalSetService hospitalSetService;


    /**
     * 上传科室接口
     *
     * @param request request
     * @return vo
     */
    @PostMapping("/saveDepartment")
    public R saveDepartment(HttpServletRequest request) {
        Map<String, Object> map = hospitalSetService.check(request);
        departmentService.save(map);
        return R.ok200();
    }

    /**
     * 分页查询科室
     *
     * @param request request
     * @return vo
     */
    @PostMapping("/department/list")
    public R findDepartment(HttpServletRequest request) {
        Map<String, Object> map = hospitalSetService.check(request);
        Page<Department> page = departmentService.getList(map);
        return R.ok200Data(page);
    }

    /**
     * 删除（逻辑删除）科室
     *
     * @param request request
     * @return vo
     */
    @PostMapping("/department/remove")
    public R removeDepartment(HttpServletRequest request) {
        Map<String, Object> map = hospitalSetService.check(request);
        departmentService.remove(map);
        return R.ok200();
    }
}

